#ifndef FFAENCODER_H
#define FFAENCODER_H

#include<vector>
extern "C"
{
#include<libavformat/avformat.h>
}

class FFAPacketQueue;

struct FFAEncoderPars{
    int sampleRate;
    int nbChannel;
    int biteRate;
    enum AVSampleFormat audioFmt;
};



class FFAEncoder
{

    struct PendingFrame {
        std::vector<uint8_t> data[8];  // 假设最大8通道
        int samples = 0;               // 缓存中的样本数
        int64_t next_pts = 0;          // 下一帧的预期PTS
    } pendingFrame;
public:
    FFAEncoder();
    ~FFAEncoder();

    void init(FFAPacketQueue* pktQueue_);

    int encode(AVFrame* frame,int streamIndex,int64_t pts,AVRational timeBase);

    FFAEncoderPars* getEncoderPars();
    AVCodecContext* getCodecCtx();

    void initAudio(AVFrame* frame);
private:
    void printError(int ret);
    AVFrame *createFrameFromPending();

private:
    FFAPacketQueue* pktQueue = nullptr;
    AVCodecContext* codecCtx = nullptr;
    FFAEncoderPars* aPars = nullptr;
    int64_t lastPts = -1;
};

#endif // FFAENCODER_H
